//
//  MainViewController.swift
//  LPSina
//
//  Created by apple on 16/3/20.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

    // MARK: - 懒加载-------------------------
    
    // 懒加载图片
   lazy var imagesarr : [String] = {
        return ["tabbar_home", "tabbar_message_center","", "tabbar_profile",
        "tabbar_discover"]}()
    
    // 懒加载发布按钮
    lazy var composeBtn : UIButton = {
        
        var composeBtn = UIButton(imageName: "tabbar_compose_icon_add", bgImageName: "tabbar_compose_button")
        
        composeBtn.center = CGPoint(x: self.tabBar.center.x, y: self.tabBar.bounds.size.height * 0.5)
        
        // 添加监听
        composeBtn.addTarget(self, action: "composeBtnClick", forControlEvents: .TouchUpInside)

        return composeBtn
    }()
    
    
    // MARK:-系统回调函数-----------------------------
    override func viewDidLoad() {
        
        // 添加按钮
        tabBar.addSubview(composeBtn)
        
        super.viewDidLoad()
    }
    
    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        
        self.setupItem()
    }
    
    // MARK:- 自定义的方法-----------------------------
    // 设置item的方法
  private  func setupItem() {
    
        for i in 0 ..< tabBar.items!.count {
            
            // 让第三个item不能点击
            if i == 2 {
                tabBar.items![i].enabled = false
            }
            
            // 设置item的图片
            tabBar.items![i].image = UIImage(named: imagesarr[i])
            tabBar.items![i].selectedImage = UIImage(named: imagesarr[i] + "_highlighted")
        }
      
    }
    
    // 按钮监听方法
  @objc private  func composeBtnClick() {
        print("点击了发送按钮")
    }
}
